home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 January / january_2001.iso / intercd / root / ^4Developers / VB / visbasdb / VBDB / VBDB Code / VB5 Code / Class 5 / Example5-2.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-08-28  |  3.6 KB  |  106 lines

  1. VERSION 5.00
  2. Object = "{00028C01-0000-0000-0000-000000000046}#1.0#0"; "DBGRID32.OCX"
  3. Begin VB.Form frmBooks 
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "Books Database"
  6.    ClientHeight    =   3345
  7.    ClientLeft      =   45
  8.    ClientTop       =   330
  9.    ClientWidth     =   6165
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   3345
  14.    ScaleWidth      =   6165
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.CommandButton cmdAll 
  17.       Caption         =   "Show All Records"
  18.       Height          =   375
  19.       Left            =   120
  20.       TabIndex        =   2
  21.       Top             =   2880
  22.       Width           =   2775
  23.    End
  24.    Begin VB.CommandButton cmdLetter 
  25.       Caption         =   "A"
  26.       Height          =   375
  27.       Index           =   0
  28.       Left            =   120
  29.       TabIndex        =   1
  30.       Top             =   2400
  31.       Width           =   1455
  32.    End
  33.    Begin VB.Data datBooks 
  34.       Caption         =   "Books"
  35.       Connect         =   "Access"
  36.       DatabaseName    =   "c:\VBDB\Working\Biblio.mdb"
  37.       DefaultCursorType=   0  'DefaultCursor
  38.       DefaultType     =   2  'UseODBC
  39.       Exclusive       =   0   'False
  40.       Height          =   300
  41.       Left            =   3000
  42.       Options         =   0
  43.       ReadOnly        =   0   'False
  44.       RecordsetType   =   1  'Dynaset
  45.       RecordSource    =   ""
  46.       Top             =   2880
  47.       Width           =   3015
  48.    End
  49.    Begin MSDBGrid.DBGrid grdBooks 
  50.       Bindings        =   "Example5-2.frx":0000
  51.       Height          =   2175
  52.       Left            =   0
  53.       OleObjectBlob   =   "Example5-2.frx":0013
  54.       TabIndex        =   0
  55.       Top             =   120
  56.       Width           =   6135
  57.    End
  58. Attribute VB_Name = "frmBooks"
  59. Attribute VB_GlobalNameSpace = False
  60. Attribute VB_Creatable = False
  61. Attribute VB_PredeclaredId = True
  62. Attribute VB_Exposed = False
  63. Option Explicit
  64. Dim SQLAll As String
  65. Private Sub cmdAll_Click()
  66. 'Show all records
  67. datBooks.RecordSource = SQLAll + "ORDER BY Authors.Author"
  68. datBooks.Refresh
  69. End Sub
  70. Private Sub cmdLetter_Click(Index As Integer)
  71. If Index <> 25 Then
  72. 'Key other than Z clicked
  73. 'Append to SQLAll to limit records to letter clicked
  74.   datBooks.RecordSource = SQLAll + "AND Authors.Author > '" + cmdLetter(Index).Caption + " ' "
  75.   datBooks.RecordSource = datBooks.RecordSource + "AND Authors.Author < '" + cmdLetter(Index + 1).Caption + " ' "
  76. 'Z Clicked
  77. 'Append to SQLAll to limit records to Z Authors
  78.   datBooks.RecordSource = SQLAll + "AND Authors.Author > 'Z' "
  79. End If
  80. datBooks.RecordSource = datBooks.RecordSource + "ORDER BY Authors.Author"
  81. datBooks.Refresh
  82. End Sub
  83. Private Sub Form_Activate()
  84. 'Show all records initially
  85. Call cmdAll_Click
  86. End Sub
  87. Private Sub Form_Load()
  88. Dim I As Integer
  89. 'Size search buttons
  90. cmdLetter(0).Width = (frmBooks.ScaleWidth - 2 * cmdLetter(0).Left) / 26
  91. 'Create 25 new buttons
  92. 'Position new button next to prior button
  93. For I = 1 To 25
  94.   Load cmdLetter(I)
  95.   cmdLetter(I).Left = cmdLetter(I - 1).Left + cmdLetter(0).Width
  96.   cmdLetter(I).Caption = Chr(Asc("A") + I)
  97.   cmdLetter(I).Visible = True
  98. Next I
  99. 'Build basic SQL statement
  100. SQLAll = "SELECT Authors.Author,Titles.Title,Publishers.[Company Name] "
  101. SQLAll = SQLAll + "FROM Authors, Titles, Publishers, [Title Author] "
  102. SQLAll = SQLAll + "WHERE Titles.ISBN = [Title Author].ISBN "
  103. SQLAll = SQLAll + "AND Authors.Au_ID = [Title Author].Au_ID "
  104. SQLAll = SQLAll + "AND Titles.PubID = Publishers.PubID "
  105. End Sub
  106.